#pragma once
#ifndef _DSST_H
#define _DSST_H
//#include<opencv2/opencv.hpp>
//#include <opencv2/highgui/highgui.hpp>
//#include "cv.h"
//#include "highgui.h"
//#include "opencv2/video/tracking.hpp"
//#include "opencv2/imgproc/imgproc.hpp"
//#include<iostream>
//#include <string>
//#include<malloc.h>  
//#include<ctime>
//#include<stdio.h>
//#include <fstream>
//#include <ctype.h>
//#include <math.h>
//#include <stdio.h>
//#include "dsp_fft32x32.h"
//#include "dsp_ifft32x32.h"
#define PI 3.141593f
#define VAR_CON 8
#define SIZE 32
#define DIG_REV(i,m,j)                                                    \
do {																		\
		unsigned _ = (i);                                                   \
		_ = ((_ & 0x33333333) << 2) | ((_ & ~0x33333333) >> 2);           \
		_ = ((_ & 0x0F0F0F0F) << 4) | ((_ & ~0x0F0F0F0F) >> 4);           \
		_ = ((_ & 0x00FF00FF) << 8) | ((_ & ~0x00FF00FF) >> 8);           \
		_ = ((_ & 0x0000FFFF) << 16) | ((_ & ~0x0000FFFF) >> 16);           \
		(j) = _ >> (m);                                                     \
} while (0)
#define MATRIXTYPE	double
struct MYMatrix
{
	unsigned  int  row, column, height;
	MATRIXTYPE* array; //使用时，必须对*array进行初始化
};
struct vec
{
	float v[144];
	float beta;
};

void schmidt(int* input, int w, int h, int* output);
//float** Make2DArray(int row, int col);
//void SetZero(float** a, int m);
//void Free2DArray(float** a, int row);
//bool SetMatrixSize(struct	MYMatrix* matrix, const unsigned  int row, const unsigned  int column, const unsigned  int height);
//void SetMatrixEle(struct	MYMatrix* matrix, MATRIXTYPE ele);
//void SetMatrixZero(struct	MYMatrix* matrix);
//bool IsNullMatrix(const struct	MYMatrix* matrix);
//void DestroyMatrix(struct	MYMatrix* matrix);
//unsigned  int MatrixCapacity(const struct	MYMatrix* matrix);
//MATRIXTYPE MatrixNorm2(const struct	MYMatrix* matrix);
//bool CopyMatrix(struct	MYMatrix* matrixB, struct	MYMatrix* matrix, unsigned  int height);
//bool MatrixMulMatrix(struct	MYMatrix* matrixC, const struct	 MYMatrix* matrixA, const struct	MYMatrix* matrixB);
//void QR(struct	MYMatrix* A, struct	MYMatrix* Q, struct	MYMatrix* R);
//void QR_CAL(double* I, int row, int col, double* Qdata, double* Rdata);
//void SortVector(MYMatrix* vector, int sign);
//void Eigenvectors(MYMatrix* eigenVector, MYMatrix* A, MYMatrix* eigenValue);
int forconfidence(int* input, int x, int y, int w, int h, int maxv);
void resizeDFT2(int wi, int hi, int* input, int wo, int ho, int* output);
void resizeDFT(int wi, int* input, int wo, int* output);
void DSP_ifft32x32(int* ptr_w, int npoints, int* ptr_x, int* ptr_y);
void DSP_fft32x32(int* ptr_w, int npoints, int* ptr_x, int* ptr_y);
void ifft(int* input, int* output, int l);
void ifft2(int* input, int* output, int w, int h);
void Hann(int size, int* hannline);
void fft2(int* input, int* output, int h, int w);
void fft(int* input, int* output, int l);
float mmax(float x, float y);
float mmin(float x, float y);
void get_translation_sample(int w, int h, unsigned char* imgd, volatile float pos[], volatile  int sz[], float ScaleFactor, unsigned short* cosw, int* out);//input cos_window output
void get_scale_sample(int w, int h, unsigned char* imgd, volatile float pos[], float base_target_sz[], float currentScaleFactor, float scaleSizeFactors[], int scalew[], float scale_model_sz[], int* xs);
void alignedimg(unsigned char* src, int Width, int Hight, unsigned char* dst, int w, int h);
void imgwarp(int* rectsrc, unsigned char* src, int width, int hight, int* rectdst, unsigned char* dst);
/////////////////fhog//////////////////////////
void gradientMagnitude(int* I, int* M, int* O, int h, int w, int d, int full);
void gradientHist(int* M, int* O, int* H, int h, int w, int bin, int nOrients, int softBin, int full);
int multiply(int ix, int iy, int n);
void dsst(volatile int* trackflag, unsigned char* imgd, int w, int h, volatile int* targetpos, volatile int* targetsize, volatile int* trackstatus);
int fastIntSqrt(int n);
int MPYHIRC(int src1, int src2);
int MPYLUHS(int src1, int src2);
int _smpyh(int src1, int src2);
int _mpyhlu(int src1, int src2);
int _mpylhu(int src1, int src2);
int _mpyu(int src1, int src2);
//void gradHistfloat(float* M, float* O, float* H, int h, int w,
//	int bin, int nOrients, int softBin, bool full);
//void gradQuantizefloat(float* O, float* M, int* O0, int* O1, float* M0, float* M1,
//	int nb, int n, float norm, int nOrients, bool full, bool interpolate);
/*
trackflag: 设置值为1传入
imgd： 	图像数据，y8
w,h 图像宽高
targetpos：跟踪区域位置。此xy为中心坐标
targetsize：跟踪区域大小
trackstatus：输出跟踪目标坐标,同样为中心坐标。 
		track.x = VIBE_WIDTH / 2 + trackstatus[2];
		track.y = VIBE_HEIGHT / 2 - trackstatus[1];
		track.w = trackstatus[4];
		track.h = trackstatus[3];
*/
void fdsst(volatile int* trackflag, unsigned char* imgd, int w, int h, 
			volatile int* targetpos, volatile int* targetsize, volatile int* trackstatus);
//void givens(float* input, int w, int h, float* output);
//void givens32(int * input, int w, int h, int* output);
//float two_norm(float x[], int begin, int end);
//float max(float x[], int n);
#endif 

